
#include "lib.h"
#include "kenocard.h"	
#include "kenoopts.h"
#include "log.h"

KenoCard::KenoCard()
{
	m_num_picks = 0;
	m_cost = 1000;
}

KenoCard::~KenoCard()
{
}

KenoCard &
KenoCard::operator = (KenoCard &card)
{
	for(int32 i = 0; i < card.m_num_picks; i++)
		m_picks[i] = card.m_picks[i];

	m_cost = card.m_cost;
	m_num_picks = card.m_num_picks;

	return *this;
}

bool8
KenoCard::SetPicks(int numpicks, uint8 *picks)
{
	if(numpicks < KenoOpts::m_min_picks || numpicks > KenoOpts::m_max_picks) return false;

	m_num_picks = numpicks;
	for(int32 i = 0; i < m_num_picks; i++)
		m_picks[i] = picks[i];

	return true;
}


bool8 
KenoCard::AddPick(uint8 pick)
{
	if(m_num_picks < KenoOpts::m_max_picks)
	{
		if (pick >= MAX_PICK)
		{
			Log::msgWarning("pick[%d] is invalid:%d", m_num_picks, pick);
		}
		m_picks[m_num_picks++] = pick;
		return true;
	}
		return false;
}


bool8 
KenoCard::IsValid()
{
	if (m_num_picks <= KenoOpts::m_max_picks && m_num_picks >= KenoOpts::m_min_picks)
	{
		for(uint8 i=0;i<m_num_picks;i++) 
		{
			if (m_picks[i] >= MAX_PICK)
				return false;
			for(uint8 j=0;j<m_num_picks;j++)
			{
				if (i != j && m_picks[i] == m_picks[j])
				{
					return false;
				}
			}
		}

		return true;
	}

	return false;
}

